#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

inline void output_words(vector<string> &words)
{
    for (auto &word : words)
    {
        cout << word << " ";
    }
    cout << endl;
}

string make_plural(size_t ctr, const string &word, const string &ending)
{
    return (ctr > 1) ? word + ending : word;
}

void elimDuplicate(vector<string> &words)
{
    sort(words.begin(), words.end());
    auto end_unique = unique(words.begin(), words.end());
    words.erase(end_unique, words.end());
}

void biggies(vector<string> &words, vector<string>::size_type sz)
{
    elimDuplicate(words);
    stable_sort(words.begin(), words.end(),
                [](const string &s1, const string &s2)
                { return s1.size() < s2.size(); });
    auto wc = find_if(words.begin(), words.end(),
                      [sz](const string &s)
                      { return s.size() >= sz; });
    auto count = words.end() - wc;
    cout << count << " " << make_plural(count, "word", "s")
         << " of length " << sz << " or longer" << endl;

    for_each(wc, words.end(),
             [](const string &s)
             { cout << s << " "; });
    cout << endl;
}

int main(int argc, char const *argv[])
{
    for (int i = 1; i < argc; ++i)
    {
        if (strcmp(argv[i], "--help") == 0)
        {
            cout << "Usage: " << argv[0] << " <input_file> <min_word_length> " << endl;
            return 1;
        }
    }

    ifstream in(argv[1]);
    if (!in)
    {
        cerr << "no input file" << endl;
        return -1;
    }
    int minlen = argc > 2 ? stoi(argv[2]) : 6;

    vector<string> words;
    string word;
    while (in >> word)
    {
        words.push_back(word);
    }
    biggies(words, minlen);
}